import zmq
import threading
context = zmq.Context()

#  Socket to talk to server
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")
sub_socket = context.socket(zmq.SUB)
sub_socket.connect("tcp://localhost:5556")
sub_socket.setsockopt_string(zmq.SUBSCRIBE, "chat:")

def sub_thread():
    while True:
        print(sub_socket.recv_string())

threading.Thread(None,sub_thread).start()

while True:
    try:
        msg = input(":")
    except EOFError:
        socket.send(b'Bye!')
        socket.close()
        break
    socket.send(bytes(msg,encoding='ascii'))
    socket.recv()
    